package tiled.simple.gwt.client;

import java.util.HashMap;

import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.user.client.ui.Image;
import tiled.simple.core.TMXRenderer;

public class MapRenderer implements TMXRenderer{

	//current context
	public Context2d context;
	public int x_delta=0;
	public int y_delta=0;
	
	private HashMap<String,Image> imagesCache = new HashMap<String, Image>();
	
	public void loadImage(String source) {
		imagesCache.put(source, new Image(source));
	}

	public void putImage(String source, int sx, int sy, int sw, int sh, int dx,int dy, int dw, int dh) {
			Image img=imagesCache.get(source);
			if(img!=null){
				ImageElement imageElement = ImageElement.as(img.getElement());
				
				context.drawImage(imageElement, sx, sy, sw, sh, dx+x_delta, dy+y_delta, dw+1, dh+1);
			}
	}
}
